<template>
	<view class="admin">
		
		<view>管理员个人信息</view>
		<view class="off" @click="setoff">注销账号</view>
		<view class="adminCont">
			<view>管理员姓名：</view>
			<view>{{this.adminName}}</view>
			<view class="admin_time">{{this.createTime}}</view>
		</view>
		<view class="adminCont">
			<view>性别：</view>
			<uni-data-checkbox v-model="radio" :localdata="sex"></uni-data-checkbox>
		</view>
		<view class="adminCont">
			<view>邮箱地址：</view>
			<uni-easyinput :placeholderStyle="placeholderStyle" :placeholder="this.adminEmail" @input="admin_email"  :styles="styles"></uni-easyinput>
		</view>
		<view class="adminCont">
			<view>密码修改：</view>
			<uni-easyinput type="password"  placeholder="不修改就不用填写"  :styles="styles" @input="admin_pwd"></uni-easyinput>
		</view>
		<view class="adminCont">
			<view>简介：</view>
			<uni-easyinput type="textarea" :placeholderStyle="placeholderStyle" :placeholder="this.descprition" @input="admin_des" :styles="styles"></uni-easyinput>
		</view>
		<view class="btn_bottom">
			<button @click="save">保存</button>
			<button @click="exit">退出</button>
		</view>
	</view>
</template>

<script>
	import http from '../../utils/http'
	export default {
		data() {
			return {
				radio:'',
				sex: [{
						text: '男',
						value: 0
					}, {
						text: '女',
						value: 1
				}],
				styles: {
					color: '#2979FF',
					borderColor: '#2979FF',
				},
				placeholderStyle: "color:#5b5b5b;font-size:32rpx",
				adminName:'',
				adminId:'',
				adminEmail:'',
				adminSex:'',
				descprition:'',
				createTime:'',
				adminPWD1:'',
				version:'',
			}
		},
		onShow() {
			this.adminName = uni.getStorageSync('adminName');
			this.get();
			},
		methods: {
			admin_email(e){
				this.adminEmail = e;
				// console.log(this.adminEmail)
			},
			admin_pwd(e){
				this.adminPWD1 = e;
				// console.log(this.adminPWD)
			},
			admin_des(e){
				this.descprition = e;
				// console.log(this.descprition)
			},
			exit(){
				uni.navigateBack({});
			},
			get(){
				http({
					url:`/admin/page`,
					params:{
						name:this.adminName,
						page:1,
						pageSize:1,
					},
					success: (res) => {
						// console.log(res.data.data.records[0])
						this.adminEmail = res.data.data.records[0].adminEmail;
						this.adminSex = res.data.data.records[0].adminSex;
						this.descprition = res.data.data.records[0].descprition;
						this.createTime = res.data.data.records[0].createTime;
						this.adminId = res.data.data.records[0].adminId;
						this.radio = this.adminSex;
						this.version = res.data.data.records[0].version;
						// console.log('liu'+this.adminPWD2)
					}
				})
			},
			save(){
				// console.log(this.radio)
				// console.log(this.adminName)
				uni.showModal({
					title:"提示",
					content:"确定保存此次修改？",
					success:(res)=>{
						// console.log(res);
						if(res.confirm){
							// console.log(itemId);
							this.adminSex = this.radio;
							if(this.adminPWD1 == ''){
								http({
									url:'/admin',
									method:'put',
									data:{
										adminId:this.adminId,
										adminEmail:this.adminEmail,
										adminSex:this.adminSex,
										descprition:this.descprition,
										// adminPWD:'null',
										version : this.version,
									},
									success:(res)=>{
										if(res.data.code == 1){
											uni.showToast({titile:'修改成功',icon:'success'})
										}else{
											uni.showToast({titile:'修改失败',icon:'error'})
										}
									}
								})
							}else{
								http({
									url:'/admin',
									method:'put',
									data:{
										adminId:this.adminId,
										adminEmail:this.adminEmail,
										adminSex:this.adminSex,
										descprition:this.descprition,
										adminPWD:this.adminPWD1,
										version : this.version,
									},
									success:(res)=>{
										if(res.data.code == 1){
											uni.showToast({titile:'修改成功',icon:'success'})
										}else{
											uni.showToast({titile:'修改失败',icon:'error'})
										}
									}
								})
							}
														
						}
						this.get();
					},
					
				})
			},
			setoff(){
				uni.showModal({
					title:"提示",
					content:"确定注销此账号？",
					success:(res)=>{
						// console.log(res);
						if(res.confirm){
							// console.log(itemId);
							http({
								url:'/admin/'+this.adminId,
								method:'delete',
								data:{
									ids:this.adaminId
								},
								success:(res)=>{
									// console.log(this)
									// console.log(res)
									if(res.data.code == 1){
										uni.showToast({titile:'注销成功',icon:'success'})
										uni.navigateTo({
											url:'./login'
										})
									}else{
										uni.showToast({titile:'注销失败',icon:'error'})
									}
									
								}
							})							
						}
					},
				})
			}
		}
	}
</script>

<style>
.admin {
	position: relative;
	height: 1250rpx;
	width: 750rpx;
	padding:50rpx 50rpx;
	margin-right: 50rpx;
	background-color: #b0b0b0;
}
.admin>view:nth-child(1) {
	margin-right: 120rpx;
	height: 70rpx;
	line-height: 70rpx;
	text-align: center; 
	color: aqua;
	border-bottom: 1px dotted #00ffff;
}
.adminCont {
	color: #00ffff;
	height: 50rpx;
	text-align: center;
	line-height: 50rpx;
	width: 650rpx;
	display: flex;
	margin-top: 60rpx;
}
.sex {
	margin-left: 300rpx;
}
.btn_bottom {
	margin-top: 190rpx;
	display: flex;
	justify-content: space-between;
}
.btn_bottom button {
	text-align: center;
	font-size: 36rpx;
	width: 140rpx;
	height: 80rpx;
	background-color: #55aaff;
}
.btn_bottom button:nth-child(1){
	margin-left: 0rpx;
}
.btn_bottom button:nth-child(2){
	margin-right: 90rpx;
}
.admin_time {
	font-size: 30rpx;
	color: #55aaff;
	margin-left: 60rpx;
} 
.off {
	width: 140rpx;
	height: 60rpx;
	/* background-color: #38b3ff; */
	position: absolute;
	top:30rpx;
	color: #ff0b54;
}
</style>